
package Interfaz;

import Negocio.Cliente;
import Negocio.Lista_clientes;
import Negocio.Producto;
import Negocio.Ciudad;
import Negocio.CiudadCliente;
import Negocio.Lista_ciudades;
import Negocio.Compras;
import Negocio.Lista_compras;
import Negocio.Factura;
import Negocio.Lista_cc;
import Negocio.Lista_facturas;
import Negocio.Lista_productos;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import java.util.Date;
import java.text.SimpleDateFormat; 
import java.util.Iterator;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTable;

public class Ventana extends javax.swing.JFrame {

    Cliente cliente = new Cliente();
    Producto producto = new Producto();
    Ciudad ciudad = new Ciudad();
    Compras compra = new Compras();
    Factura factura = new Factura();
    Lista_clientes listaClientes = new Lista_clientes();
    Lista_ciudades listaCiudades = new Lista_ciudades();
    Lista_compras listaCompras = new Lista_compras();
    Lista_facturas listaFacturas = new Lista_facturas();
    Lista_cc listaCC = new Lista_cc();
    DefaultTableModel modeloCliente = new DefaultTableModel();
    DefaultTableModel modeloFact = new DefaultTableModel();
    DefaultTableModel modeloCiudad = new DefaultTableModel();
    DefaultTableModel modeloProducto = new DefaultTableModel();
    DefaultComboBoxModel comboCiudad = new DefaultComboBoxModel();
    Validacion validar = new Validacion();
    SimpleDateFormat formato;
    Date hoy = new Date();
    Lista_productos listaproductos = new Lista_productos();
    CiudadCliente cc = new CiudadCliente();
   
    
    public Ventana() {
        initComponents();        
        formato=new SimpleDateFormat("yyyy-MM-dd");
        lblFecha.setText(formato.format(hoy));
        lblIdFact.setText("");
        lblFechaE.setText("");
        tblClientes.setModel(modeloCliente);
        modeloCliente.addColumn("Cedula");
        modeloCliente.addColumn("Nombre");
        modeloCliente.addColumn("Apellido");
        modeloCliente.addColumn("Calle");
        modeloCliente.addColumn("Numero Casa");
        modeloCliente.addColumn("Telefono");
        modeloCliente.addColumn("Ciudad");
        tblproductos.setModel(modeloProducto);
        modeloProducto.addColumn("Id");
        modeloProducto.addColumn("Nombre");
        modeloProducto.addColumn("Cantidad");
        modeloProducto.addColumn("Precio");
        tblFactura.setModel(modeloFact);
        modeloFact.addColumn("Id Producto");
        modeloFact.addColumn("Nombre");
        modeloFact.addColumn("Cantidad");
        modeloFact.addColumn("Precio");
        tblCiudades.setModel(modeloCiudad);
        modeloCiudad.addColumn("Id");
        modeloCiudad.addColumn("Nombre");     
        lblTotal.setText("");
    }
    
    public void limpiarTabla(JTable tbl){
        int aux = tbl.getRowCount();
        do{
            try{
                DefaultTableModel temp = (DefaultTableModel) tbl.getModel();
                temp.removeRow(temp.getRowCount()-1);
            }
            catch(ArrayIndexOutOfBoundsException e){
            }
            aux--;
        }while(aux > 0);
    }
    
    public void listarCompras(int id){
            listaCompras.listar(id);
            double precio;
            double suma=0;
            ArrayList compras = new ArrayList();
            compras = listaCompras.getCompras();
            DefaultTableModel temp = (DefaultTableModel) tblFactura.getModel();
            for (int i = tblFactura.getRowCount() - 1; i >= 0; i--) {
                temp.removeRow(i);
            }
            for (int i = 0; i < compras.size(); i++) {
                Compras otraCompra = new Compras();
                otraCompra = (Compras) compras.get(i);
                producto.setId(otraCompra.getIdProd());
                producto.buscar();
                precio=otraCompra.getCantidad()*producto.getPrecio();
                suma=precio+suma;
                lblTotal.setText(suma+" $");
                Object nuevo[] = {otraCompra.getIdProd(), producto.getNombre(), otraCompra.getCantidad(),  precio};
                temp.addRow(nuevo);            
            }
            tblFactura.setModel(temp);
    }
    
    public void agregarCiudadesCombo() {
        comboCiudad.removeAllElements();
        listaCiudades.listar();
        ArrayList ciudades = listaCiudades.getCiudades();
        Iterator it = ciudades.iterator();
        while (it.hasNext()) {
            Ciudad c = (Ciudad) it.next();
            comboCiudad.addElement(c.getNombre());
        }
        cmbciudades.setModel(comboCiudad);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        txtIdCiudad = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtNombreCiudad = new javax.swing.JTextField();
        btnAgregarCiu = new javax.swing.JButton();
        btnBuscarCiu = new javax.swing.JButton();
        btnModificarCiu = new javax.swing.JButton();
        btnEliminarCiu = new javax.swing.JButton();
        btnActualizarCiu = new javax.swing.JButton();
        btnLimpiarCiu = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblCiudades = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtidpro = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtnombrepro = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtcantidadpro = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtpreciopro = new javax.swing.JTextField();
        btnagregarpro = new javax.swing.JButton();
        btnbuscarpro = new javax.swing.JButton();
        btnmodificarpro = new javax.swing.JButton();
        btneliminarpro = new javax.swing.JButton();
        btnactualizarpro = new javax.swing.JButton();
        btnlimpiarpro = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblproductos = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblClientes = new javax.swing.JTable();
        txtCedula = new javax.swing.JTextField();
        txtNombreCli = new javax.swing.JTextField();
        txtApellidoCli = new javax.swing.JTextField();
        txtCalleCli = new javax.swing.JTextField();
        txtNumeroCli = new javax.swing.JTextField();
        txtTelefonoCli = new javax.swing.JTextField();
        btnAgregarCli = new javax.swing.JButton();
        btnBuscarCli = new javax.swing.JButton();
        btnModificarCli = new javax.swing.JButton();
        btnEliminarCli = new javax.swing.JButton();
        btnActualizarCli = new javax.swing.JButton();
        btnLimpiarCli = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        cmbciudades = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        lblIdFact = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        lblFecha = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        txtCedulaFact = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        txtIdProdFact = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        txtCantidadFact = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblFactura = new javax.swing.JTable();
        btnCrearFact = new javax.swing.JButton();
        btnEliminarFact = new javax.swing.JButton();
        btnLimpiarFact = new javax.swing.JButton();
        btnAgregarCompra = new javax.swing.JButton();
        btnFinalizarFact = new javax.swing.JButton();
        btnBuscarFact = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        lblFechaE = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        lblTotal = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTabbedPane1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane1MouseClicked(evt);
            }
        });

        jPanel4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel4MouseClicked(evt);
            }
        });

        jLabel11.setText("Id:");

        txtIdCiudad.setEnabled(false);

        jLabel12.setText("Nombre");

        txtNombreCiudad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNombreCiudadKeyPressed(evt);
            }
        });

        btnAgregarCiu.setText("Agregar");
        btnAgregarCiu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarCiuActionPerformed(evt);
            }
        });

        btnBuscarCiu.setText("Buscar");
        btnBuscarCiu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarCiuActionPerformed(evt);
            }
        });

        btnModificarCiu.setText("Modificar");
        btnModificarCiu.setEnabled(false);
        btnModificarCiu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarCiuActionPerformed(evt);
            }
        });

        btnEliminarCiu.setText("Eliminar");
        btnEliminarCiu.setEnabled(false);
        btnEliminarCiu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarCiuActionPerformed(evt);
            }
        });

        btnActualizarCiu.setText("Actualizar");
        btnActualizarCiu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnActualizarCiuMouseClicked(evt);
            }
        });
        btnActualizarCiu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarCiuActionPerformed(evt);
            }
        });

        btnLimpiarCiu.setText("Limpiar");
        btnLimpiarCiu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLimpiarCiuMouseClicked(evt);
            }
        });
        btnLimpiarCiu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarCiuActionPerformed(evt);
            }
        });

        tblCiudades.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Id", "Nombre"
            }
        ));
        jScrollPane3.setViewportView(tblCiudades);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGap(167, 167, 167)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNombreCiudad, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                    .addComponent(txtIdCiudad))
                .addGap(98, 98, 98)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btnActualizarCiu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnEliminarCiu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnModificarCiu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnBuscarCiu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnAgregarCiu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnLimpiarCiu, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(121, 121, 121))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(87, 87, 87)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(btnAgregarCiu)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(txtIdCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnBuscarCiu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel12)
                        .addComponent(txtNombreCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnModificarCiu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnEliminarCiu)
                .addGap(3, 3, 3)
                .addComponent(btnActualizarCiu)
                .addGap(4, 4, 4)
                .addComponent(btnLimpiarCiu)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(66, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Ciudad", jPanel4);

        jPanel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel3MouseClicked(evt);
            }
        });

        jLabel7.setText("Id");
        jLabel7.setEnabled(false);

        txtidpro.setEnabled(false);

        jLabel8.setText("Nombre");

        txtnombrepro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtnombreproKeyPressed(evt);
            }
        });

        jLabel9.setText("Cantidad");

        txtcantidadpro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtcantidadproKeyPressed(evt);
            }
        });

        jLabel10.setText("Precio");

        txtpreciopro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtprecioproKeyPressed(evt);
            }
        });

        btnagregarpro.setText("Agregar");
        btnagregarpro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnagregarproActionPerformed(evt);
            }
        });

        btnbuscarpro.setText("Buscar");
        btnbuscarpro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnbuscarproActionPerformed(evt);
            }
        });

        btnmodificarpro.setText("Modificar");
        btnmodificarpro.setEnabled(false);
        btnmodificarpro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnmodificarproActionPerformed(evt);
            }
        });

        btneliminarpro.setText("Eliminar");
        btneliminarpro.setEnabled(false);
        btneliminarpro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btneliminarproActionPerformed(evt);
            }
        });

        btnactualizarpro.setText("Actualizar");
        btnactualizarpro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnactualizarproActionPerformed(evt);
            }
        });

        btnlimpiarpro.setText("Limpiar");
        btnlimpiarpro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnlimpiarproActionPerformed(evt);
            }
        });

        tblproductos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Id", "Nombre", "Cantidad", "Precio"
            }
        ));
        jScrollPane2.setViewportView(tblproductos);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnmodificarpro, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnbuscarpro, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnagregarpro, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(67, 67, 67))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(106, 106, 106)
                        .addComponent(jLabel10)
                        .addGap(465, 465, 465)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnlimpiarpro, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnactualizarpro)
                            .addComponent(btneliminarpro, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(67, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(93, 93, 93)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtnombrepro, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                        .addComponent(txtidpro)
                        .addComponent(txtcantidadpro)
                        .addComponent(txtpreciopro))
                    .addContainerGap(380, Short.MAX_VALUE)))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(btnagregarpro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnbuscarpro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnmodificarpro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btneliminarpro)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnactualizarpro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnlimpiarpro)
                .addGap(1, 1, 1)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(81, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(38, 38, 38)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(txtidpro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(txtnombrepro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(txtcantidadpro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(txtpreciopro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(328, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Productos", jPanel3);

        jPanel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel2MouseClicked(evt);
            }
        });

        jLabel1.setText("Cedula:");

        jLabel2.setText("Nombre");

        jLabel3.setText("Apellido");

        jLabel4.setText("Direccion Calle:");

        jLabel5.setText("Direccion Numero:");

        jLabel6.setText("Telefono:");

        tblClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Cedula", "Nombre", "Apellido", "Calle", "Numero Casa", "Telefono", "Ciudad"
            }
        ));
        jScrollPane1.setViewportView(tblClientes);

        txtCedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCedulaKeyPressed(evt);
            }
        });

        txtNombreCli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNombreCliKeyPressed(evt);
            }
        });

        txtApellidoCli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtApellidoCliKeyPressed(evt);
            }
        });

        txtCalleCli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCalleCliKeyPressed(evt);
            }
        });

        txtNumeroCli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNumeroCliKeyPressed(evt);
            }
        });

        txtTelefonoCli.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTelefonoCliKeyPressed(evt);
            }
        });

        btnAgregarCli.setText("Agregar");
        btnAgregarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarCliActionPerformed(evt);
            }
        });

        btnBuscarCli.setText("Buscar");
        btnBuscarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarCliActionPerformed(evt);
            }
        });

        btnModificarCli.setText("Modificar");
        btnModificarCli.setEnabled(false);
        btnModificarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarCliActionPerformed(evt);
            }
        });

        btnEliminarCli.setText("Eliminar");
        btnEliminarCli.setEnabled(false);
        btnEliminarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarCliActionPerformed(evt);
            }
        });

        btnActualizarCli.setText("Actualizar");
        btnActualizarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarCliActionPerformed(evt);
            }
        });

        btnLimpiarCli.setText("Limpiar");
        btnLimpiarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarCliActionPerformed(evt);
            }
        });

        jLabel14.setText("Ciudad");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4)
                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtCedula)
                            .addComponent(txtNombreCli)
                            .addComponent(txtApellidoCli)
                            .addComponent(txtCalleCli)
                            .addComponent(txtNumeroCli, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addComponent(txtTelefonoCli)
                            .addComponent(cmbciudades, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(123, 123, 123)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnActualizarCli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnEliminarCli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnModificarCli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnBuscarCli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnAgregarCli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnLimpiarCli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(128, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtNombreCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtApellidoCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtCalleCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtNumeroCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtTelefonoCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(cmbciudades, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnAgregarCli)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuscarCli)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnModificarCli)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEliminarCli)
                        .addGap(3, 3, 3)
                        .addComponent(btnActualizarCli)
                        .addGap(4, 4, 4)
                        .addComponent(btnLimpiarCli)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(53, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Cliente", jPanel2);

        jLabel13.setText("Nro. Factura:");

        lblIdFact.setText("jLabel14");

        jLabel15.setText("Fecha:");

        lblFecha.setText("jLabel16");

        jLabel17.setText("Cedula:");

        txtCedulaFact.setEnabled(false);
        txtCedulaFact.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCedulaFactKeyPressed(evt);
            }
        });

        jLabel19.setText("Producto Id:");

        txtIdProdFact.setEnabled(false);
        txtIdProdFact.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtIdProdFactKeyPressed(evt);
            }
        });

        jLabel18.setText("Cantidad:");

        txtCantidadFact.setEnabled(false);
        txtCantidadFact.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCantidadFactKeyPressed(evt);
            }
        });

        tblFactura.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Producto Id", "Cantidad", "Precio"
            }
        ));
        jScrollPane4.setViewportView(tblFactura);

        btnCrearFact.setText("Crear");
        btnCrearFact.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCrearFactActionPerformed(evt);
            }
        });

        btnEliminarFact.setText("Eliminar");
        btnEliminarFact.setEnabled(false);
        btnEliminarFact.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarFactActionPerformed(evt);
            }
        });

        btnLimpiarFact.setText("Limpiar");
        btnLimpiarFact.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarFactActionPerformed(evt);
            }
        });

        btnAgregarCompra.setText("Agregar");
        btnAgregarCompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarCompraActionPerformed(evt);
            }
        });

        btnFinalizarFact.setText("Finalizar");
        btnFinalizarFact.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFinalizarFactActionPerformed(evt);
            }
        });

        btnBuscarFact.setText("Buscar");
        btnBuscarFact.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarFactActionPerformed(evt);
            }
        });

        jLabel16.setText("Fecha Emision:");

        lblFechaE.setText("jLabel20");

        jLabel20.setText("Total:");

        lblTotal.setText("jLabel21");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnAgregarCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jLabel13)
                        .addGap(18, 18, 18)
                        .addComponent(lblIdFact)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(36, 36, 36)
                                        .addComponent(jLabel16)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblFechaE, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(183, 183, 183)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel18)
                                            .addComponent(jLabel19)
                                            .addComponent(jLabel17))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtCedulaFact)
                                            .addComponent(txtIdProdFact)
                                            .addComponent(txtCantidadFact, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 186, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(44, 44, 44)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnBuscarFact, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnEliminarFact, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnLimpiarFact, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnFinalizarFact, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnCrearFact, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(87, 87, 87))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(344, 344, 344)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(lblFecha)
                    .addComponent(jLabel13)
                    .addComponent(lblIdFact))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnCrearFact)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAgregarCompra))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel16)
                        .addComponent(lblFechaE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(txtCedulaFact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(txtIdProdFact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(txtCantidadFact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnBuscarFact)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEliminarFact)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLimpiarFact)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnFinalizarFact)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(lblTotal))
                .addContainerGap(78, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Factura", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 40, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnActualizarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarCliActionPerformed
        actualizarcliente();  
    }//GEN-LAST:event_btnActualizarCliActionPerformed

    private void btnAgregarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarCliActionPerformed
        // TODO add your handling code here:        
        cliente.setCedula(txtCedula.getText());
        cliente.setNombre(txtNombreCli.getText());
        cliente.setApellido(txtApellidoCli.getText());
        cliente.setDir_calle(txtCalleCli.getText());
        cliente.setDir_numero(txtNumeroCli.getText());
        cliente.setTelefono(txtTelefonoCli.getText());
        cc.setCedula(txtCedula.getText());
        if(comboCiudad.getSelectedItem()!=null){
            String nombre = (String) comboCiudad.getSelectedItem();
            ciudad.setNombre(nombre);
            ciudad.buscarNombre();
            cc.setId(ciudad.getId());
            cliente.grabar();
            cc.grabar();  
        }
        else{
            JOptionPane.showMessageDialog(null, "Primero agregue una ciudad");
        }
        btnLimpiarCli.doClick();
        btnActualizarCli.doClick();
        
    }//GEN-LAST:event_btnAgregarCliActionPerformed

    private void btnBuscarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarCliActionPerformed
        try{
            String cedu =  JOptionPane.showInputDialog("Ingrese una cedula");
            if(cedu.equals("")==false){
                cliente.setCedula(cedu);
                cliente.buscar();
                if (cliente.getNombre() == null) {            
                    txtNombreCli.setText("");
                    txtApellidoCli.setText("");
                    txtCalleCli.setText("");
                    txtNumeroCli.setText("");
                    txtTelefonoCli.setText("");
                    btnModificarCli.setEnabled(false);
                    btnEliminarCli.setEnabled(false);
                } else {
                    btnModificarCli.setEnabled(true);
                    btnEliminarCli.setEnabled(true);
                    txtCedula.setEnabled(false);
                    txtCedula.setText(cliente.getCedula());
                    txtNombreCli.setText(cliente.getNombre());
                    txtApellidoCli.setText(cliente.getApellido());
                    txtNombreCli.setEnabled(false);
                    txtApellidoCli.setEnabled(false);
                    txtCalleCli.setText(cliente.getDir_calle());
                    txtNumeroCli.setText(cliente.getDir_numero());
                    txtTelefonoCli.setText(cliente.getTelefono()+"");
                    txtCedula.setText(cedu);
                }
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, "Operacion Cancelada");
        }
    }//GEN-LAST:event_btnBuscarCliActionPerformed

    private void btnModificarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarCliActionPerformed
        // TODO add your handling code here:
        cliente.setDir_calle(txtCalleCli.getText());
        cliente.setDir_numero(txtNumeroCli.getText());
        cliente.setTelefono(txtTelefonoCli.getText());
        
        String nombre = comboCiudad.getSelectedItem().toString();
        ciudad.setNombre(nombre);
        ciudad.buscarNombre();
        cc.setId(ciudad.getId());
        cc.buscar();
        if(cc.getCedula()==null){
            cc.setCedula(txtCedula.getText());
            cc.grabar();
        }else{
            cc.modificar();
            cliente.modificar();
        }
        btnModificarCli.setEnabled(false);
        btnEliminarCli.setEnabled(false);
        txtCedula.setEnabled(true);
        txtNombreCli.setEnabled(true);
        txtApellidoCli.setEnabled(true);       
    }//GEN-LAST:event_btnModificarCliActionPerformed


    private void btnagregarproActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnagregarproActionPerformed
        producto.setNombre(txtnombrepro.getText());
        producto.setCantidad(Integer.parseInt(txtcantidadpro.getText()));
        producto.setPrecio(Double.parseDouble(txtpreciopro.getText()));
        producto.grabar(); 
        btnlimpiarpro.doClick();
        btnactualizarpro.doClick();
    }//GEN-LAST:event_btnagregarproActionPerformed

    private void btnbuscarproActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbuscarproActionPerformed
       try{
        int id = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la Id"));
       producto.setId(id);
       producto.buscar();
       if (producto.getNombre() == null) {
           txtidpro.setText("");
           txtnombrepro.setText("");
           txtcantidadpro.setText("");
           txtpreciopro.setText("");
       }
       else{
            btnmodificarpro.setEnabled(true);
            btneliminarpro.setEnabled(true);
            txtidpro.setText(String.valueOf(id));
            txtidpro.setText(String.valueOf(producto.getId()));
            txtnombrepro.setEnabled(false);
            txtnombrepro.setText(producto.getNombre());
            txtcantidadpro.setText(String.valueOf(producto.getCantidad()));
            txtpreciopro.setText(String.valueOf(producto.getPrecio()));
       }}
       catch(Exception e){
            JOptionPane.showMessageDialog(null, "Operacion Cancelada");
        }
    }//GEN-LAST:event_btnbuscarproActionPerformed

    private void btnEliminarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarCliActionPerformed
        // TODO add your handling code here:
        int opc = JOptionPane.showConfirmDialog(rootPane, "Seguro desea eliminar los datos?", "choose one", JOptionPane.YES_NO_OPTION); 
        if (opc==0){          
            cliente.setCedula(txtCedula.getText());
            cc.setCedula(txtCedula.getText());           
            cc.eliminar();
            cliente.eliminar();
        }
        btnModificarCli.setEnabled(false);
        btnEliminarCli.setEnabled(false);
        txtCedula.setText("");
        txtNombreCli.setText("");
        txtApellidoCli.setText("");
        txtCalleCli.setText("");
        txtNumeroCli.setText("");
        txtTelefonoCli.setText("");
        txtCedula.setEnabled(true);
        txtNombreCli.setEnabled(true);
        txtApellidoCli.setEnabled(true);
    }//GEN-LAST:event_btnEliminarCliActionPerformed


    private void btnLimpiarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarCliActionPerformed
        // TODO add your handling code here:
        txtCedula.setText("");
        txtNombreCli.setText("");
        txtApellidoCli.setText("");
        txtCalleCli.setText("");
        txtNumeroCli.setText("");
        txtTelefonoCli.setText("");
        txtCedula.setEnabled(true);
        txtNombreCli.setEnabled(true);
        txtApellidoCli.setEnabled(true);
    }//GEN-LAST:event_btnLimpiarCliActionPerformed


    private void btnmodificarproActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnmodificarproActionPerformed
        producto.setNombre(txtnombrepro.getText());
        producto.setCantidad(Integer.parseInt(txtcantidadpro.getText()));
        producto.setPrecio(Double.parseDouble(txtpreciopro.getText()));
        producto.modificar();
        btnmodificarpro.setEnabled(false);
        btneliminarpro.setEnabled(false);
    }//GEN-LAST:event_btnmodificarproActionPerformed

    private void btneliminarproActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarproActionPerformed
        int opc = JOptionPane.showConfirmDialog(rootPane, "Seguro desea eliminar los datos?", "choose one", JOptionPane.YES_NO_OPTION); 
        if (opc==0){                    
            producto.eliminar();
        }
        btnmodificarpro.setEnabled(false);
        btneliminarpro.setEnabled(false);
        txtCedula.setText("");
        txtNombreCli.setText("");
        txtApellidoCli.setText("");
        txtCalleCli.setText("");
        txtNumeroCli.setText("");
        txtTelefonoCli.setText("");
    }//GEN-LAST:event_btneliminarproActionPerformed

    private void btnAgregarCiuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarCiuActionPerformed
        // TODO add your handling code here:
        ciudad.setNombre(txtNombreCiudad.getText());
        ciudad.grabar();
        btnLimpiarCiu.doClick();
        btnActualizarCiu.doClick();
        
        
    }//GEN-LAST:event_btnAgregarCiuActionPerformed

    private void btnBuscarCiuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarCiuActionPerformed
        // TODO add your handling code here:
        try{
            int id = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la Id"));
            ciudad.setId(id);
            ciudad.buscar();
            if (ciudad.getNombre() == null) {
                txtIdCiudad.setText("");
                txtNombreCiudad.setText("");
            }
            else{
                btnModificarCiu.setEnabled(true);
                btnEliminarCiu.setEnabled(true);
                txtIdCiudad.setText(ciudad.getId()+"");
                txtNombreCiudad.setText(ciudad.getNombre());
            }       
        } catch(Exception e){
            JOptionPane.showMessageDialog(null, "Operacion Cancelada");
        }
    }//GEN-LAST:event_btnBuscarCiuActionPerformed

    private void btnModificarCiuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarCiuActionPerformed
        // TODO add your handling code here:
        ciudad.setNombre(txtNombreCiudad.getText());
        ciudad.modificar();
        btnModificarCiu.setEnabled(false);
        btnEliminarCiu.setEnabled(false);
    }//GEN-LAST:event_btnModificarCiuActionPerformed

    private void btnEliminarCiuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarCiuActionPerformed
        // TODO add your handling code here:
        int opc = JOptionPane.showConfirmDialog(rootPane, "Seguro desea eliminar los datos?", "choose one", JOptionPane.YES_NO_OPTION); 
        if (opc==0){                    
            ciudad.setId(Integer.parseInt(txtIdCiudad.getText()));
            cc.setId(Integer.parseInt(txtIdCiudad.getText()));
            cc.eliminarId();
            ciudad.eliminar();                        
        }
        btnModificarCiu.setEnabled(false);
        btnEliminarCiu.setEnabled(false);
        txtIdCiudad.setText("");
        txtNombreCiudad.setText("");
    }//GEN-LAST:event_btnEliminarCiuActionPerformed

    private void btnActualizarCiuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarCiuActionPerformed

       actualizarciudad();
    }//GEN-LAST:event_btnActualizarCiuActionPerformed

    private void btnLimpiarCiuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarCiuActionPerformed
        // TODO add your handling code here:
        txtIdCiudad.setText("");
        txtNombreCiudad.setText("");
    }//GEN-LAST:event_btnLimpiarCiuActionPerformed

    private void btnEliminarFactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarFactActionPerformed
        // TODO add your handling code here:
        try{
            int id = (int) tblFactura.getValueAt(tblFactura.getSelectedRow(), 0);
            compra.setIdProd(id);
            compra.eliminar();        
            listarCompras(Integer.parseInt(lblIdFact.getText()));
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Para eliminar debe seleccionar un producto de la lista");
        }
        
    }//GEN-LAST:event_btnEliminarFactActionPerformed

    private void btnLimpiarFactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarFactActionPerformed
        // TODO add your handling code here:
        txtCedulaFact.setText("");
        txtIdProdFact.setText("");
        txtCantidadFact.setText("");
        limpiarTabla(tblFactura);
    }//GEN-LAST:event_btnLimpiarFactActionPerformed

    private void btnCrearFactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCrearFactActionPerformed
        // TODO add your handling code here:
        factura.setFecha(lblFecha.getText());
        factura.grabar();
        txtCedulaFact.setEnabled(true);
        txtIdProdFact.setEnabled(true);
        txtCantidadFact.setEnabled(true);        
        lblIdFact.setText(String.valueOf(listaFacturas.getId()));
        btnCrearFact.setEnabled(false);
    }//GEN-LAST:event_btnCrearFactActionPerformed

    private void btnAgregarCompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarCompraActionPerformed
        // TODO add your handling code here:
        int cant;
        try{
            compra.setIdFact(Integer.parseInt(lblIdFact.getText()));
            compra.setIdProd(Integer.parseInt(txtIdProdFact.getText()));
            compra.setCedula(txtCedulaFact.getText());
            compra.setCantidad(Integer.parseInt(txtCantidadFact.getText())); 
            cliente.setCedula(txtCedulaFact.getText());
            cliente.buscar();
            if(cliente.getNombre()!=null){
                producto.setId(Integer.parseInt(txtIdProdFact.getText()));
                producto.buscar();
                if(producto.getCantidad()>=compra.getCantidad()){
                    cant=producto.getCantidad()-compra.getCantidad();
                    producto.setCantidad(cant);
                    producto.modificar();
                    compra.grabar();
                    txtCedulaFact.setEnabled(false);
                    listarCompras(Integer.parseInt(lblIdFact.getText()));
                }
                else {
                    JOptionPane.showMessageDialog(null, "Solo existen "+producto.getCantidad()+" productos: "+producto.getNombre());
                }
            }
            txtIdProdFact.setText("");
            txtCantidadFact.setText("");
        } catch(NumberFormatException e){
            JOptionPane.showMessageDialog(null, "Faltan ingresar datos");
        }
    }//GEN-LAST:event_btnAgregarCompraActionPerformed

    private void btnBuscarFactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarFactActionPerformed
        // TODO add your handling code here:
        try{
            int id = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la Id"));
            compra.setIdFact(id);        
            compra.buscar();
            if (compra.getCedula() == null){
                factura.setId(id);
                factura.buscar();
                if(factura.getFecha() != null){
                    factura.eliminar();
                }
                txtCedulaFact.setText("");
                txtIdProdFact.setText("");
                txtCantidadFact.setText("");
            }
            else{
                 btnEliminarFact.setEnabled(true);
                 lblIdFact.setText(String.valueOf(id));
                 lblFechaE.setText(factura.getFecha());             
                 txtCedulaFact.setText(compra.getCedula());
                 listarCompras(id);             
            }
        }
        catch(NumberFormatException e){
            JOptionPane.showMessageDialog(null, "Operacion Cancelada");
        }
    }//GEN-LAST:event_btnBuscarFactActionPerformed
/*
    private void btnactualizarproActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        // TODO add your handling code here:
        
    }                                                

    private void btnlimpiarproActionPerformed(java.awt.event.ActionEvent evt) {                                              
        
    }                                             
*/    
    private void btnactualizarproActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnactualizarproActionPerformed
        // TODO add your handling code here:
        actualizarproducto();
    }//GEN-LAST:event_btnactualizarproActionPerformed

    private void btnlimpiarproActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnlimpiarproActionPerformed
        txtidpro.setText("");
        txtnombrepro.setText("");
        txtcantidadpro.setText("");
        txtpreciopro.setText("");
        limpiarTabla(tblproductos);
    }//GEN-LAST:event_btnlimpiarproActionPerformed

    private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseClicked
        cmbciudades.removeAllItems();
        agregarCiudadesCombo();        
        actualizarcliente();
        actualizarciudad();
        actualizarproducto();
    }//GEN-LAST:event_jTabbedPane1MouseClicked

    private void btnFinalizarFactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinalizarFactActionPerformed
        // TODO add your handling code here:
        int id = Integer.parseInt(lblIdFact.getText());
        factura.setId(id);
        factura.buscar();
        compra.setIdFact(factura.getId());
        compra.buscarFact();
        if(compra.getCedula()==null || listaCompras.getCompras()==null){            
            factura.eliminar();
        }
        txtCedulaFact.setText("");
        txtIdProdFact.setText("");
        txtCantidadFact.setText("");
        txtCedulaFact.setEnabled(false);
        txtIdProdFact.setEnabled(false);
        txtCantidadFact.setEnabled(false);
        lblIdFact.setText("");
        limpiarTabla(tblFactura);
        btnCrearFact.setEnabled(true);
    }//GEN-LAST:event_btnFinalizarFactActionPerformed


    private void txtNombreCiudadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreCiudadKeyPressed
        // TODO add your handling code here:
        validar.ValidarPalabras(txtNombreCiudad);
    }//GEN-LAST:event_txtNombreCiudadKeyPressed

    private void txtnombreproKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtnombreproKeyPressed
        // TODO add your handling code here:
        validar.ValidarPalabras(txtnombrepro);
    }//GEN-LAST:event_txtnombreproKeyPressed

    private void txtcantidadproKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtcantidadproKeyPressed
        // TODO add your handling code here:
        validar.ValidarNumeros(txtcantidadpro);
    }//GEN-LAST:event_txtcantidadproKeyPressed

    private void txtprecioproKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtprecioproKeyPressed
        // TODO add your handling code here:
        validar.ValidarDecimales(txtpreciopro);
    }//GEN-LAST:event_txtprecioproKeyPressed

    private void btnActualizarCiuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnActualizarCiuMouseClicked
  
    }//GEN-LAST:event_btnActualizarCiuMouseClicked

    private void btnLimpiarCiuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLimpiarCiuMouseClicked
       
    }//GEN-LAST:event_btnLimpiarCiuMouseClicked

    private void txtCedulaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCedulaKeyPressed
        // TODO add your handling code here:
        validar.ValidarNumeros(txtCedula);
    }//GEN-LAST:event_txtCedulaKeyPressed

    private void txtNombreCliKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreCliKeyPressed
        // TODO add your handling code here:
        validar.ValidarPalabras(txtNombreCli);
    }//GEN-LAST:event_txtNombreCliKeyPressed

    private void txtApellidoCliKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoCliKeyPressed
        // TODO add your handling code here:
        validar.ValidarPalabras(txtApellidoCli);
    }//GEN-LAST:event_txtApellidoCliKeyPressed

    private void txtCalleCliKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCalleCliKeyPressed
        // TODO add your handling code here:
        validar.ValidarPalabras(txtCalleCli);
    }//GEN-LAST:event_txtCalleCliKeyPressed

    private void txtNumeroCliKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNumeroCliKeyPressed
        // TODO add your handling code here:
        validar.ValidarNumCasa(txtNumeroCli);
    }//GEN-LAST:event_txtNumeroCliKeyPressed

    private void txtTelefonoCliKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoCliKeyPressed
        // TODO add your handling code here:
        validar.ValidarNumeros(txtTelefonoCli);
    }//GEN-LAST:event_txtTelefonoCliKeyPressed

    private void txtCedulaFactKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCedulaFactKeyPressed
        // TODO add your handling code here:
        validar.ValidarNumeros(txtCedulaFact);
    }//GEN-LAST:event_txtCedulaFactKeyPressed

    private void txtIdProdFactKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIdProdFactKeyPressed
        // TODO add your handling code here:
        validar.ValidarNumeros(txtIdProdFact);
    }//GEN-LAST:event_txtIdProdFactKeyPressed

    private void txtCantidadFactKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadFactKeyPressed
        // TODO add your handling code here:
        validar.ValidarNumeros(txtCantidadFact);
    }//GEN-LAST:event_txtCantidadFactKeyPressed

    private void jPanel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel3MouseClicked
        // TODO add your handling code here:
        actualizarproducto();
    }//GEN-LAST:event_jPanel3MouseClicked

    private void jPanel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel4MouseClicked
        // TODO add your handling code here:
         actualizarciudad();
    }//GEN-LAST:event_jPanel4MouseClicked

    private void jPanel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel2MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel2MouseClicked

    private void actualizarciudad(){
        listaCiudades.listar();
        ArrayList ciudades = new ArrayList();
        ciudades = listaCiudades.getCiudades();
        DefaultTableModel temp = (DefaultTableModel) tblCiudades.getModel();
        for (int i = tblCiudades.getRowCount() - 1; i >= 0; i--) {
            temp.removeRow(i);
        }
        for (int i = 0; i < ciudades.size(); i++) {
            Ciudad otraCiudad = new Ciudad();
            otraCiudad = (Ciudad) ciudades.get(i);
            Object nuevo[] = {otraCiudad.getId(), otraCiudad.getNombre()};
            temp.addRow(nuevo);
        }
        tblCiudades.setModel(temp);
    }
    
    private void actualizarcliente(){
        listaClientes.listar();
        ArrayList clientes = new ArrayList();
        clientes = listaClientes.getClientes();
        DefaultTableModel temp = (DefaultTableModel) tblClientes.getModel();
        for (int i = tblClientes.getRowCount() - 1; i >= 0; i--) {
            temp.removeRow(i);
        }
        for (int i = 0; i < clientes.size(); i++) {
            Cliente otroCliente = new Cliente();
            otroCliente = (Cliente) clientes.get(i);
            cc.setCedula(otroCliente.getCedula());
            cc.buscar();
            ciudad.setId(cc.getId());
            ciudad.buscar();
            Object nuevo[] = {otroCliente.getCedula(), otroCliente.getNombre(), otroCliente.getApellido(), otroCliente.getDir_calle(), otroCliente.getDir_numero(), otroCliente.getTelefono(), ciudad.getNombre()};
            temp.addRow(nuevo);
        }
        tblClientes.setModel(temp);      
       }
       
    private void actualizarproducto(){
        listaproductos.listar();
        ArrayList prods = new ArrayList();
        prods = listaproductos.getProductos();
        DefaultTableModel temp = (DefaultTableModel) tblproductos.getModel();
        for (int i = tblproductos.getRowCount() - 1; i >= 0; i--) {
            temp.removeRow(i);
        }
        for (int i = 0; i < prods.size(); i++) {
            Producto prod = new Producto();
            prod = (Producto) prods.get(i);
            Object nuevo[] = {prod.getId(), prod.getNombre(), prod.getCantidad(), prod.getPrecio()};
            temp.addRow(nuevo);
        }
        tblproductos.setModel(temp);
    }
       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
              
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Ventana().setVisible(true);
            }
        });

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizarCiu;
    private javax.swing.JButton btnActualizarCli;
    private javax.swing.JButton btnAgregarCiu;
    private javax.swing.JButton btnAgregarCli;
    private javax.swing.JButton btnAgregarCompra;
    private javax.swing.JButton btnBuscarCiu;
    private javax.swing.JButton btnBuscarCli;
    private javax.swing.JButton btnBuscarFact;
    private javax.swing.JButton btnCrearFact;
    private javax.swing.JButton btnEliminarCiu;
    private javax.swing.JButton btnEliminarCli;
    private javax.swing.JButton btnEliminarFact;
    private javax.swing.JButton btnFinalizarFact;
    private javax.swing.JButton btnLimpiarCiu;
    private javax.swing.JButton btnLimpiarCli;
    private javax.swing.JButton btnLimpiarFact;
    private javax.swing.JButton btnModificarCiu;
    private javax.swing.JButton btnModificarCli;
    private javax.swing.JButton btnactualizarpro;
    private javax.swing.JButton btnagregarpro;
    private javax.swing.JButton btnbuscarpro;
    private javax.swing.JButton btneliminarpro;
    private javax.swing.JButton btnlimpiarpro;
    private javax.swing.JButton btnmodificarpro;
    private javax.swing.JComboBox cmbciudades;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblFecha;
    private javax.swing.JLabel lblFechaE;
    private javax.swing.JLabel lblIdFact;
    private javax.swing.JLabel lblTotal;
    private javax.swing.JTable tblCiudades;
    private javax.swing.JTable tblClientes;
    private javax.swing.JTable tblFactura;
    private javax.swing.JTable tblproductos;
    private javax.swing.JTextField txtApellidoCli;
    private javax.swing.JTextField txtCalleCli;
    private javax.swing.JTextField txtCantidadFact;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtCedulaFact;
    private javax.swing.JTextField txtIdCiudad;
    private javax.swing.JTextField txtIdProdFact;
    private javax.swing.JTextField txtNombreCiudad;
    private javax.swing.JTextField txtNombreCli;
    private javax.swing.JTextField txtNumeroCli;
    private javax.swing.JTextField txtTelefonoCli;
    private javax.swing.JTextField txtcantidadpro;
    private javax.swing.JTextField txtidpro;
    private javax.swing.JTextField txtnombrepro;
    private javax.swing.JTextField txtpreciopro;
    // End of variables declaration//GEN-END:variables

}
